import request from "@/router/axios";
import qs from "qs";
import Cookies from "js-cookie";
import md5 from 'js-md5'
import { baseUrl } from "@/config/env";
export const loginByUsername = (param) =>
  request({
    url: baseUrl + "/login",
    method: "post",
    meta: {
      isToken: false,
    },
    data: {
      account :param.username,
      password : md5(param.password),
      code : param.code
    },
  });


export const loginByPhone = (param) =>
  request({
    url: baseUrl + "/login/phone",
    method: "post",
    meta: {
      isToken: false,
    },
    data: {
      account :param.phone,
      password : param.code,
      code : param.tenantcode
    },
  });

export const getValidateCode = (mobile,tenantCode) =>
  request({
    url: baseUrl + "/login/" + mobile,
    method: "get",
    params: {tenantCode},
  });

  export const sendMsgCode = (mobile) =>
  request({
    url: baseUrl + "/login/send/" + mobile,
    method: "get",
  });

export const getUserInfoByJava = (data) =>
  request({
    url: baseUrl + "/user_/getCurUserInfo",
    method: "post",
    headers: { "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", Authorization: Cookies.get("TOKEN") },
    data: qs.stringify(data),
  });

export const getUserInfo = () =>
  request({
    url: "" + "/user/getUserInfo",
    method: "get",
  });

export const refeshToken = () =>
  request({
    url: "" + "/user/refesh",
    method: "post",
  });

export const getMenu = (systemId) =>
  request({
    url: baseUrl + "/modules/vue",
    method: "get",
    params: {
      'systemId':systemId
    },
  });

export const getUserPermission = () =>
  request({
    url: baseUrl + "/modules/other",
    method: "get",
  });

export const getTopMenu = () =>
  request({
    url: baseUrl + "/modules/common",
    method: "get",
  });

export const sendLogs = (list) =>
  request({
    url: "" + "/user/logout",
    method: "post",
    data: list,
  });

export const logout = () =>
  request({
    url: baseUrl + "/login/logout",
    // meta: {
    //   isToken: false,
    // },
    method: "post",
  });

/* orm增加数据*/
export function logAdd(data) {
  return request(`${baseUrl}/login/add-clue`, {
    method: "post",
    data,
  });
}

/* 修改密码 */
export function updatePass(userId,data){
  return request(`${baseUrl}/users/${userId}/updatePassword`, {
    method: "put",
    data
  })
}

/* 忘记密码 */
export const resetPass = (data) =>{
  request({
    url: `${baseUrl}/users/forget-password`,
    method: "post",
    data
  });
}
//计算请假时间（小时）
export const getLeaveTime = (params) => request({
  url:baseUrl+'/getLeaveTime',
  method:'get',
  params
})

//计算请假时间（天）
export const getLeaveDay = (params) => request({
  url:baseUrl+'/getLeaveDay',
  method:'get',
  params
})
//计算加班时间
export const getOverTime = (params) => request({
  url:baseUrl+'/getOverTime',
  method:'get',
  params
})
//获取用户详细信息
export const getUserDetails = (params) => request({
  url:baseUrl+'/users/getUserDetails',
  method:'get',
  params
})
export const getUserDetailsById = (params) => request({
  url:baseUrl+'/users/getUserDetailsById',
  method:'get',
  params
})

//获取考勤组下所有人员信息/schedualreleation/getGroupMembers/{groupId}
export const getGroupMembers = (groupId) => request({
  url:baseUrl+`/groupuser/all/${groupId}`,
  method:'get'
})
// 根据是否需要排班，来获取不同的排班列表
export const getAllByFlag = (params) => request({
  url:baseUrl+`/shift/getAllByFlag`,
  method:'get',
  params
})
//获取城市列表/city
export const getCityList = (params) => request({
  url:baseUrl+'/city',
  method:'get',
  params
})
//查询人某天的班次情况
export const getSchedualTimes = (params) => request({
  url:baseUrl+'/schedualreleation/getSchedualTimes',
  method:'get',
  params
})

// 新增排班
export function addSchedual(data){
  return request(`${baseUrl}/shift`,{
    method:"post",
    data
  })
}

// 查询排班列表
export const getSchedualList = (params) => request({
  url:baseUrl+'/shift/getPageList',
  method:'get',
  params
})
// 查询排班列表
export const getSchedualAll = (params) => request({
  url:baseUrl+'/shift/getAll',
  method:'get',
  params
})
//修改班次
export function updateSchedual(id, data) {
  return request(`${baseUrl}/shift/${id}`, {
    method: "put",
    data
  })
}
// 获取弹性规则
export const getElastic = (id) => request({
  url:`${baseUrl}/shift/${id}/elastic`,
  method:'get'
})
// 提交弹性规则
export function putElastic(id, data) {
  return request(`${baseUrl}/shift/${id}/elastic`, {
    method: "put",
    data
  })
}

//新增考勤组
export function addAttendanceGroup(data){
  return request(`${baseUrl}/attendancegroup`,{
    method:"post",
    data
  })
}
//修改考勤组
export function UpdateSchedualgroup(id, data) {
  return request(`${baseUrl}/attendancegroup/${id}`, {
    method: "put",
    data
  })
}
// 查询考勤组 schedualgroup
export const getAttendanceGroupList = (params) => request({
  url:baseUrl+'/attendancegroup',
  method:'get',
  params
})
// 查询自己所在权限的考勤组
export const getAttendanceGroupManageList = (params) => request({
  url:baseUrl+'/attendancegroup/manage/pageList',
  method:'get',
  params
})

// 查询考勤组 schedualgroup 带分页 指定管理员
export const attendanceManageList = (params) => request({
  url:baseUrl+'/attendancegroup/manage/noPage',
  method:'get',
  params
})

// 获取个人所在考勤组 新接口
export const getSchedualOwnerGroup = () => request({
  url:baseUrl+'/schedual/owner/web/group',
  method:'get'
})

//删除考勤组/schedualgroup/{id}
export const delAttendancegroup = (ids) => request({
  url: baseUrl + '/attendancegroup/' + ids,
  method: 'delete'
});
//批量设置群组人员结构
export function insertReleations(data){
  return request(`${baseUrl}/groupuser/branch`,{
    method:"post",
    data
  })
}
//批量设置群组人员结构
export function deleteReleation(data){
  return request(`${baseUrl}/groupuser/branch`,{
    method:"delete",
    data
  })
}

//获取考勤组详情
export const getGroupDetails = (groupId) => request({
  url:`${baseUrl}/schedualgroup/getDetails/${groupId}`,
  method: 'get',
});
//获取部门下所有的岗位
export const getPostListByDepartmentId = (departmentId) => request({
  url:`${baseUrl}/companies/posts/tree?Department_Id=${departmentId}`,
  method: 'get',
});

//换班流程审批通过接口

export function changeClassProcessSuccess(data){
  return request(`${baseUrl}/exchange_class/changeClassProcessSuccess`,{
    method:"post",
    data
  })
}
//下载模板
export const downloadExcleTemplate = (groupId, date) => request({
  url: `${baseUrl}/schedualExcle/download?date=${date}&groupId=${groupId}`,
  method: 'get',
});

/* 根据用户Id查询用户考勤组 */
export const getGroupByUserId = (id) => request({
  url: baseUrl + `/schedualgroup/getGroupByUserId/${id}`,
  method: 'get'
});
//获取用户剩余所有节假日getAllHolidaysByUserId
export const getAllHolidaysByUserId = (params) => request({
  url:baseUrl+'/getAllHolidaysByUserId',
  method:'get',
  params
})
//新建文件夹
export function newFolder(data){
  return request(`${baseUrl}/file-manager/addFolder`,{
    method:"post",
    data
  })
}

// 下载文件
export const downloadFile = (fileId) => request({
  url:baseUrl+'/file-manager/downloadFile?fileId='+fileId,
  method:'get',
})
//获取所有的文件
export const getAllFileList = (params) => request({
  url:baseUrl+'/file-manager/listFilesWithPermission',
  method:'get',
  params
})
//查询文件下的文件夹和文件

export const getFileByParentId = (parentId) => request({
  url: baseUrl + `/file-manager/getFileByParentId/${parentId}`,
  method: 'get'
});



//删除文件及其文件夹
export const onlyDelete = (params) => request({
  url:`${baseUrl}/file-manager/batchDelete?fileIds=${fileIds}`,
  method: 'delete',
  data:params
}
);
//批量删除文件及其文件夹
export const batchDelete = (fileIds) => request({
    url:`${baseUrl}/file-manager/batchDelete`,
    method: 'delete',
    data:fileIds
  }
);

// export const batchMove = (targetFolderId,fileIds) => request({
//   url:`${baseUrl}/file-manager/batchMove/${targetFolderId}`,
//   method: 'post',
//   data:fileIds
// });


//单文件上传
// http://42.193.101.147:2828/file-manager/uploadFile?isPassword=0&isSecurity=0&permissionLevel=2

export const uploadFile = (file,isPassword,isSecurity) => request({
  // url: baseUrl + '/file-manager/uploadFile',
  url:`${baseUrl}/file-manager/uploadFile?isPassword=${isPassword}&isSecurity=${isSecurity}&permissionLevel=2`,
  method: 'post',
  data:file
});
// 文件重命名 
export const updateFileName = (fileId,fileName,type) => request({
  url:`${baseUrl}/file-manager/updateFileName?fileId=${fileId}&fileName=${fileName}&type=${type}`,
  method: 'put',
});
//设置密码/file-manager/changePassword
export const setFolderPassword = (fileId,password,type) => request({
  url:`${baseUrl}/file-manager/changePassword?fileId=${fileId}&password=${password}&type=${type}`,
  method: 'put',
});
//修改密码/file-manager/changePassword
export const changeFolderPassword = (fileId,oldPassword,password,type) => request({
  url:`${baseUrl}/file-manager/changePassword?fileId=${fileId}&oldPassword=${oldPassword}&password=${password}&type=${type}`,
  method: 'put',
});
// 取消文件/文件夹密码
export const cancleFolderPassword = (fileId,oldPassword,type) => request({
  url:`${baseUrl}/file-manager/cancleFolderPassword?fileId=${fileId}&oldPassword=${oldPassword}&type=${type}`,
  method: 'put',
});
//移动文件或文件夹
export const moveFolderOrFile = (fileId,folderId) => request({
  url:`${baseUrl}/file-manager/removeFile?fileId=${fileId}&folderId=${folderId}`,
  method: 'put',
});

// 批量移动文件
export const batchMove = (targetFolderId,fileIds) => request({
  url:`${baseUrl}/file-manager/batchMove/${targetFolderId}`,
  method: 'post',
  data:fileIds
});
//获取地区
export const getAreaInfo = code =>
  request({
    url: baseUrl + "/data-items/" + code + "/detail/tree",
    method: "get"
  });

//获取下所有的人员
export const getCUrrentDepartmentUserList = (id) => request({
  url:`${baseUrl}/im/${id}/users`,
  method: 'get',
});

//获取物品清单/
export const getPurchaseList = (limit,size,keyword) => request({
  url:`${baseUrl}/purchaselist?limit=${limit}&size=${size}&keyword=${keyword}`,
  method:'get',
})
//发票识别
export const distInvoice = (data) => request({
  url:`${baseUrl}/invoice/file-or-url`,
  method:'post',
  data
})

